# 自动提款机模拟界面

# 定义一个用于存放账户信息的字典
accountlist = {
    "zhangsan": {"password": "123456", "balance": 1000},
    "lisi": {"password": "123456", "balance": 2000},
    "wangwu": {"password": "123456", "balance": 5000}
}


# 账户登陆
def login():
    name = input("请输入账户名: ")
    if name in accountlist.keys():
        password = input("请输入密码： ")
        if password in accountlist[name]["password"] == password:
            return True, "登陆成功！您好！", name
        return False, "账户名或密码错误！请重新登陆！", name

    else:
        return False, "账户名不存在！",name


# 定义一个账户余额信息输出函数
def show_balance(name):
    return accountlist[name]["balance"]


# 定义存款后输出余额函数
def show_deposits(name, money):
    accountlist[name]["balance"] += money
    return accountlist[name]["balance"]


# 定义取款后输出余额函数
def show_draw(name, money):
    accountlist[name]["balance"] -= money
    return accountlist[name]["balance"]


while True:
    ok, msg, name = login()
    print(msg)
    if not ok:
        continue
    while True:
        # 输出提款机操作窗口
        print("=" * 10, "请选择您所需要的服务", "=" * 10)
        print("{0:1}{1:10}{2:10}".format(" ", "1.查询余额", "2.存款"))
        print("{0:1}{1:11}{2:10}".format(" ", "3.取款", "4.退出"))
        print("=" * 39)
        key = input("输入对应的选择")
        # 根据键盘值，判断并执行对应的操作
        if key == "1":
            balance = show_balance(name)
            print("查询成功，您的账户余额为:{0}".format(balance))
            input("按回车键返回上级一菜单： ")
        elif key == "2":
            money = input("请输入存入金额： ")
            balance = show_deposits(name, int(money))
            print("存款成功，您的账户余额为:{0}".format(balance))
            input("按回车键返回上级一菜单： ")
        elif key == "3":
            money = input("请输入取现金额： ")
            if accountlist[name]["balance"] < int(money):
                print("对不起，余额不足！ ")
            else:
                balance = show_draw(name, int(money))
                print("取现成功，您的账户余额为:{0}".format(balance))
            input("按回车键返回上级一菜单： ")
        elif key == "4":
            print("=" * 14, "欢迎您下次光临！", "=" * 14)
            break
        else:
            print("=" * 12, "无效的键盘输入!", "=" * 12)
